package demo3;

class Solution {
     int[] sum = {31,28,31,30,31,30,31,31,30,31,30,31};
    public int daysBetweenDates(String date1, String date2) {
       
      int[] dateInt1 = parseDate(date1) , dateInt2 = parseDate(date2);
        return Math.abs(
            bj(dateInt1[0],dateInt1[1],dateInt1[2])
            - bj(dateInt2[0],dateInt2[1] ,dateInt2[2])
        );
    }

    public int bj(int year, int month , int day){
     int day1 = day -1 ;
     
     for(int i = month ; i > 1 ; i--){
          day1 += sum[i-1-1] ;
     }
      if ((year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) && month > 2) day1 ++ ;
     day1+= (365*(year-1) + (year-1)/4 - (year-1)/100 + (year-1)/400 );
      return day1 ;
    }
     



    public int[] parseDate(String date){
      return new int[]{Integer.valueOf(date.substring(0,4)),
                        Integer.valueOf(date.substring(5,7)),
                        Integer.valueOf(date.substring(8,10))};
    }


}